home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH5 / EMAGA5 BOOK CODE / control / client / misc / presetkeys.cs next >
Encoding:
Text File  |  2006-06-22  |  5.1 KB  |  166 lines

  1. //============================================================================
  2. // control/client/misc/presetkeys.cs
  3. //
  4. // Copyright (c) 2003, 2006 Kenneth C. Finney
  5. //============================================================================
  6.  
  7. if ( IsObject(PlayerKeymap) )  // If we already have a player key map,
  8.    PlayerKeymap.delete();        // delete it so that we can make a new one
  9. new ActionMap(PlayerKeymap);
  10.  
  11. $movementSpeed = 1;             // m/s   for use by movement functions
  12.  
  13.  
  14. //------------------------------------------------------------------------------
  15. // Non-remapable binds
  16. //------------------------------------------------------------------------------
  17.  
  18. function DoExitGame()
  19. {
  20.    MessageBoxYesNo( "Quit Mission", "Exit from this Mission?", "Quit();", "");
  21. }
  22.  
  23.  
  24. //============================================================================
  25. // Motion Functions
  26. //============================================================================
  27.  
  28. function GoLeft(%val)
  29. //----------------------------------------------------------------------------
  30. // "strafing"
  31. //----------------------------------------------------------------------------
  32. {
  33.    $mvLeftAction = %val;
  34. }
  35.  
  36. function GoRight(%val)
  37. //----------------------------------------------------------------------------
  38. // "strafing"
  39. //----------------------------------------------------------------------------
  40. {
  41.    $mvRightAction = %val;
  42. }
  43.  
  44. function GoAhead(%val)
  45. //----------------------------------------------------------------------------
  46. // running forward
  47. //----------------------------------------------------------------------------
  48. {
  49.    $mvForwardAction = %val;
  50. }
  51.  
  52. function BackUp(%val)
  53. //----------------------------------------------------------------------------
  54. // running backwards
  55. //----------------------------------------------------------------------------
  56. {
  57.    $mvBackwardAction = %val;
  58. }
  59.  
  60. function DoYaw(%val)
  61. //----------------------------------------------------------------------------
  62. // looking, spinning or aiming horizontally by mouse or joystick control
  63. //----------------------------------------------------------------------------
  64. {
  65.    $mvYaw += %val * ($cameraFov / 90) * 0.02;
  66. }
  67.  
  68. function DoPitch(%val)
  69. //----------------------------------------------------------------------------
  70. // looking vertically by mouse or joystick control
  71. //----------------------------------------------------------------------------
  72. {
  73.    $mvPitch += %val * ($cameraFov / 90) * 0.02;
  74. }
  75.  
  76. function DoJump(%val)
  77. //----------------------------------------------------------------------------
  78. // momentary upward movement, with character animation
  79. //----------------------------------------------------------------------------
  80. {
  81.    $mvTriggerCount2++;
  82. }
  83.  
  84. //============================================================================
  85. // View Functions
  86. //============================================================================
  87.  
  88. function Toggle3rdPPOVLook( %val )
  89. //----------------------------------------------------------------------------
  90. // enable the "free look" feature. As long as the mapped key is pressed,
  91. // the player can view his avatar by moving the mouse around.
  92. //----------------------------------------------------------------------------
  93. {
  94.    if ( %val )
  95.       $mvFreeLook = true;
  96.    else
  97.       $mvFreeLook = false;
  98. }
  99.  
  100. function MouseAction(%val)
  101. {
  102.    $mvTriggerCount0++;
  103. }
  104.  
  105. $firstPerson = true;
  106. function Toggle1stPPOV(%val)
  107. //----------------------------------------------------------------------------
  108. // switch between 1st and 3rd person point-of-views.
  109. //----------------------------------------------------------------------------
  110. {
  111.    if (%val)
  112.    {
  113.       $firstPerson = !$firstPerson;
  114.       ServerConnection.setFirstPerson($firstPerson);
  115.    }
  116. }
  117.  
  118.  
  119. //============================================================================
  120. // keyboard control mappings
  121. //============================================================================
  122. // these ones available when player is in game
  123. PlayerKeymap.Bind( mouse, button0, MouseAction ); // left mouse button
  124. PlayerKeymap.Bind(keyboard, w, GoAhead);
  125. PlayerKeymap.Bind(keyboard, s, BackUp);
  126. PlayerKeymap.Bind(keyboard, a, GoLeft);
  127. PlayerKeymap.Bind(keyboard, d, GoRight);
  128. PlayerKeymap.Bind(keyboard, space, DoJump );
  129. PlayerKeymap.Bind(keyboard, z, Toggle3rdPPOVLook );
  130. PlayerKeymap.Bind(keyboard, tab, Toggle1stPPOV );
  131. PlayerKeymap.Bind(mouse, xaxis, DoYaw );
  132. PlayerKeymap.Bind(mouse, yaxis, DoPitch );
  133.  
  134. // these ones are always available
  135.  
  136. GlobalActionMap.Bind(keyboard, escape, DoExitGame);
  137. GlobalActionMap.Bind(keyboard, tilde, ToggleConsole);
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. function dropCameraAtPlayer(%val)
  145. {
  146.    if (%val)
  147.       commandToServer('dropCameraAtPlayer');
  148. }
  149.  
  150. function dropPlayerAtCamera(%val)
  151. {
  152.    if (%val)
  153.       commandToServer('DropPlayerAtCamera');
  154. }
  155. function toggleCamera(%val)
  156. {
  157.    if (%val)
  158.    {
  159.       commandToServer('ToggleCamera');
  160.       }
  161. }
  162.  
  163. PlayerKeymap.bind(keyboard, "F8", dropCameraAtPlayer);
  164. PlayerKeymap.bind(keyboard, "F7", dropPlayerAtCamera);
  165.  
  166. PlayerKeymap.bind(keyboard, "F6", toggleCamera);